#include "stdafx.h"
#include "net/ICMPSocket.hpp"
#include "net/ICMPSocketImpl.hpp"

NET_NAMESPACE_BEGIN

CICMPSocket::CICMPSocket(CIPAddress::Family family, int dataSize, int ttl, int timeout)
	: CSocket(new CICMPSocketImpl(family, dataSize, ttl, timeout)),
	m_dataSize(dataSize), 
	m_ttl(ttl),
	m_timeout(timeout)
{
}

CICMPSocket::CICMPSocket(const CSocket& socket) : CSocket(socket)
{
	if (!dynamic_cast<CICMPSocketImpl*>(impl()))
		throw InvalidArgumentException("Cannot assign incompatible socket");
}

CICMPSocket::CICMPSocket(CSocketImpl* pImpl) : CSocket(pImpl)
{
	if (!dynamic_cast<CICMPSocketImpl*>(impl()))
		throw InvalidArgumentException("Cannot assign incompatible socket");
}

CICMPSocket::~CICMPSocket()
{
}


CICMPSocket& CICMPSocket::operator = (const CSocket& socket)
{
	if (dynamic_cast<CICMPSocketImpl*>(socket.impl()))
		CSocket::operator = (socket);
	else
		throw InvalidArgumentException("Cannot assign incompatible socket");
	return *this;
}

int CICMPSocket::sendTo(const CSocketAddress& address, int flags)
{
	return impl()->sendTo(0, 0, address, flags);
}

int CICMPSocket::receiveFrom(CSocketAddress& address, int flags)
{
	return impl()->receiveFrom(0, 0, address, flags);
}

NET_NAMESPACE_END
